#include "widget.h"
#include "ui_widget.h"
#include <QDebug>
#include <QListWidget>
#include <QListWidgetItem>
#include <QTreeWidgetItem>
#include <QStringList>
#include <QTreeWidget>
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
    ui->setupUi(this);
//按钮组
    ui->rbtnMan->setChecked(true);//单选按钮默认值
    connect(ui->rbtnWoman,&QRadioButton::clicked,[=](){
    qDebug()<<"性别：女";
    });
    //多选按钮
    //2:选中
    //0：未选中
    //当在ui页面勾选tristate时，1表示半选中状态
    ui->rap->setTristate(true);
    connect(ui->rap,&QCheckBox::stateChanged,[=](int state){
    qDebug()<<state;
    });

//QlistWidget使用
    // QListWidgetItem* item=new QListWidgetItem("举头望明月");
    // //单行放入
    // ui->listWidget->addItem(item);
    // //设置水平居中
    // item->setTextAlignment(Qt::AlignHCenter);
    QStringList list;
    list<<"举头望明月"<<"低头思故乡";
    ui->listWidget->addItems(list);


//QTreeWidget使用
    ui->treeWidget->setHeaderLabels(QStringList()<<"英雄"<<"英雄介绍");
    QTreeWidgetItem* fItem= new QTreeWidgetItem(QStringList()<<"分路");
    //加载顶层节点
    ui->treeWidget->addTopLevelItem(fItem);

    //追加子节点
    QStringList hero1;
    hero1<<"亚索"<<"疾风剑客";
    QTreeWidgetItem* l1=new QTreeWidgetItem(hero1);
    fItem->addChild(l1);
//QTableWidget
    ui->tableWidget->setColumnCount(3);//设置列数
    // 设置水平表头
    ui->tableWidget->setHorizontalHeaderLabels(QStringList()<<"姓名"<<"性别"<<"年龄");
    //设置行数
    ui->tableWidget->setRowCount(5);
    //设置正文
    //ui->tableWidget->setItem(0,0,new QTableWidgetItem("盖亚"));
    QStringList nameList;
    nameList<<"盖亚"<<"赛罗"<<"金角"<<"迪迦"<<"贝斯";
    QList<QString> sexList;
    sexList<<"男"<<"女"<<"男"<<"女"<<"男";
    for(int i=0;i<5;++i)
    {
    int col=0;
    ui->tableWidget->setItem(i,col++,new QTableWidgetItem(nameList[i]));
    ui->tableWidget->setItem(i,col++,new QTableWidgetItem(sexList.at(i)));
    ui->tableWidget->setItem(i,col++,new QTableWidgetItem(QString::number(i+18)));
    }
//-------------------------------------------------------
    //栈控件的使用
    // 设置默认定位
    ui->stackedWidget->setCurrentIndex(1);
    //scrollArea按钮
    connect(ui->btn_ScorllArea,&QPushButton::clicked,[=](){
    ui->stackedWidget->setCurrentIndex(0);
    });
    //TabWidget
    connect(ui->btn_TabWidget,&QPushButton::clicked,[=](){
    ui->stackedWidget->setCurrentIndex(1);
    });
    //toolBox
    connect(ui->btn_ToolBox,&QPushButton::clicked,[=](){
    ui->stackedWidget->setCurrentIndex(2);
    });

    //下拉框
    ui->comboBox->addItem("奔驰");
    ui->comboBox->addItem("宝马");
    ui->comboBox->addItem("奥迪");
    //点击按钮，选中宝马
    connect(ui->btn_combobox,&QPushButton::clicked,[=](){
    ui->comboBox->setCurrentText("宝马");
    // ui->comboBox->setCurrentIndex(2);
    });
    //lable标签可以显示图片，包括动图gif
    ui->lbl_image->setPixmap(QPixmap());
    // QMovie movie=new QMovie();
    // ui->label_movie->setMovie(movie);
    // movie->start();//播放动图

}
Widget::~Widget()
{
delete ui;
}
